package com.qqtech.qquan.user.service;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.qqtech.core.common.exception.BizzException;
import com.qqtech.core.frame.dao.BaseDao;
import com.qqtech.core.frame.service.BaseServiceImpl;
import com.qqtech.qquan.user.dao.UserMessageDao;
import com.qqtech.qquan.user.model.UserMessage;

@Service
public class UserMessageServiceImpl extends BaseServiceImpl<UserMessage>
		implements UserMessageService {
	public static final Logger log = LoggerFactory.getLogger(UserMessageServiceImpl.class);
	
	@Resource
	private UserMessageDao userMessageDao;

	@Override
	protected BaseDao<UserMessage> getBaseDao() {
		return userMessageDao;
	}

	@Override
	public int addMessage(UserMessage message)  throws BizzException{
		if(message==null){
			throw new BizzException("留言信息为空！");
		}
		if(message.getFromId()==null){
			throw new BizzException("留言者id为空！");
		}
		if(message.getToId()==null){
			throw new BizzException("留言接收人id为空！");
		}
		return userMessageDao.insert(message);
	}

	@Override
	public UserMessage queryLastMessage(Integer fromId, Integer toId) {
		return userMessageDao.queryLastMessage(fromId, toId);
	}
	
}